﻿// -----------------------------------------------------------------------
// <copyright file="Duck.cs" company="Microsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Cspl.AnimalFight.Lib.Data
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Cspl.AnimalFight.Lib.Interfaces;
    using Cspl.AnimalFight.Lib.EventHandlers;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class Duck : AnimalBase, IAttack, IAttackable
    {
        #region Field
 
        #endregion

        #region Event
        public event AttackDelegate AttackEvent;
        #endregion

        #region Property

        #endregion

        #region Method
        public void Attack(string targetName)
        {
            if (this._animalName != targetName)
            {
                if (IsExistOnBattleField("attack") && AttackEvent != null)
                {
                    AttackEventHandler e = new AttackEventHandler
                    {
                        AnimalTargetName = targetName,
                        AP = this.AP
                    };

                    AttackEvent(this, e);
                }
            }
            else
            {
                Console.WriteLine("Cannot attack itself.");
            }
            
        }

        public override void Escape()
        {
            if (IsExistOnBattleField("escape"))
            {
                this.HasEscaped = true;
                Console.Write("The {0} has ", this.Name);
                Console.BackgroundColor = ConsoleColor.Red;
                Console.WriteLine("escaped");
                Console.ResetColor();
                Console.WriteLine();
            } 
        }

        public void Attacked(int ap)
        {

            if (IsExistOnBattleField("attack"))
            {
                int realDp = this.DP;

                this.HP -= (ap - realDp);
                this.HP = this.HP < 0 ? 0 : this.HP;

                Console.WriteLine("HP is decreased {0}", realDp - ap);
                if (this.HP <= 0)
                {
                    Console.Write("The {0} is ", this.Name);
                    Console.BackgroundColor = ConsoleColor.Red;
                    Console.WriteLine("dead");
                    Console.ResetColor();
                    this.IsDead = true;
                }

            }
        }
        #endregion


        
    }
}
